<?php

use App\Kuafu\Invoice\Controller\Ext\InvoiceController;
use App\Kuafu\Pay\BasePay;
use App\Kuafu\WaiMai\Controller\Ext\DyWaiMaiCallbackController;
use Illuminate\Support\Facades\Route;
use App\Kuafu\Pay\Controller\Ext\CallbackController;
use App\Kuafu\WaiMai\Controller\Ext\MtWaiMaiCallbackController;
use App\Kuafu\WaiMai\Controller\Ext\ElmWaiMaiCallbackController;

/*
|--------------------------------------------------------------------------
| API Pay Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

// 回调相关路由
Route::prefix('callback')->group(function () {

    // 支付回调
    Route::middleware('payCallback')->group(function () {
        Route::post('wx/pay', [CallbackController::class, 'wxPay']);
        Route::any('fy/pay', [CallbackController::class, 'fyPay']);
        Route::any('mybank/pay', [CallbackController::class, 'mybank']);

        Route::any('alipay/appPay', [CallbackController::class, 'aliAppPay']);
        Route::any('wx/appPay/{sysType}', [CallbackController::class, 'wxAppPay']); // 监控一阵子接口调用，没调用就能删了
        Route::any('wx/appPayV2/{sysType}/{company}', [CallbackController::class, 'wxAppPayV2']);
    });

    // 美团
    Route::prefix('mt')->group(function () {

        // 映射店铺
        Route::post('storeMap', [CallbackController::class, 'mtStoreMap']);
        Route::post('unstoreMap', [CallbackController::class, 'mtUnstoreMap']);
    });


    // 美团外卖
    Route::prefix('mtWaiMai')->middleware(['MtWaiMaiCheckSign', 'WaiMaiCallbackAfter'])->group(function () {

        // 推送订单
        Route::any('pushOrder', [MtWaiMaiCallbackController::class, 'pushOrder']);

        // 商家接单
        Route::any('acceptOrder', [MtWaiMaiCallbackController::class, 'acceptOrder']);

        // 催单推送
        Route::any('warnOrder', [MtWaiMaiCallbackController::class, 'warnOrder']);

        // 隐私号降级
        Route::any('privacyDegrade', [MtWaiMaiCallbackController::class, 'privacyDegrade']);

        // 取消订单
        Route::any('cancelOrder', [MtWaiMaiCallbackController::class, 'cancelOrder']);

        // 全额退款
        Route::any('refundTotalOrder', [MtWaiMaiCallbackController::class, 'refundTotalOrder']);

        // 部分退款
        Route::any('refundPartOrder', [MtWaiMaiCallbackController::class, 'refundPartOrder']);

        // 完成订单
        Route::any('completeOrder', [MtWaiMaiCallbackController::class, 'completeOrder']);

        // 配送订单
        Route::any('deliveringOrder', [MtWaiMaiCallbackController::class, 'deliveringOrder']);

        // 结算推送
        Route::any('billOrder', [MtWaiMaiCallbackController::class, 'billOrder']);

    });

    // 饿了么外卖
    Route::prefix('elmWaiMai')->middleware(['ElmWaiMaiCheckSign', 'WaiMaiCallbackAfter'])->group(function () {

        // 消息推送
        Route::any('push', [ElmWaiMaiCallbackController::class, 'push']);
    });

    //盟度电子发票
    Route::prefix('invoice')->group(function () {
        Route::post('uploadNotify', [InvoiceController::class, 'uploadNotify']);
        Route::post('cancelNotify', [InvoiceController::class, 'cancelNotify']);
        Route::post('init', [InvoiceController::class, 'init']);
        Route::get('jumpUrl', [InvoiceController::class, 'jumpUrl']);

    });

    // 飞书机器人回调机器人
    Route::prefix('robot')->group(function () {
        Route::prefix('feishu')->group(function () {
            Route::any('rms', [\App\Kuafu\Robot\Controller\Feishu\RmsController::class, 'orderStatistical']);
        });
    });

    // 抖音外卖
    Route::prefix('dyWaiMai')->middleware(['DyWaiMaiCheckSign', 'WaiMaiCallbackAfter'])->group(function () {

        // 推送 根据event区分业务
        Route::any('push', [DyWaiMaiCallbackController::class, 'push']);

        // 用户申请退款消息
        Route::any('takeoutRefundNotice', [DyWaiMaiCallbackController::class, 'takeoutRefundNotice']);

    });

});
